package com.hqully.smartfumehood.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqully.smartfumehood.common.utils.QueryVoUtil;
import com.hqully.smartfumehood.common.vo.QueryVo;
import com.hqully.smartfumehood.entity.Laboratory;
import com.hqully.smartfumehood.entity.dto.LaboratoryDto;
import com.hqully.smartfumehood.mapper.LaboratoryMapper;
import com.hqully.smartfumehood.service.LaboratoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *     实验室服务实现类
 * </p>
 * @author liulingyu
 * @date 2022-05-08 14:39
 * @version 1.0
 */
@Service
public class LaboratoryServiceImpl extends ServiceImpl<LaboratoryMapper, Laboratory> implements LaboratoryService {

    @Autowired
    private LaboratoryMapper  laboratoryMapper;
    
    @Override
    public PageInfo<LaboratoryDto> findAllLaboratory(QueryVo queryVo) {
        PageHelper.startPage(queryVo.getPageNum(),queryVo.getPageSize(),true);

        List<LaboratoryDto> laboratoryList = laboratoryMapper.findAllLaboratory(queryVo.getQuery());

        PageInfo<LaboratoryDto> laboratoryPageInfo = new PageInfo<>(laboratoryList);


        return laboratoryPageInfo;
    }

    @Override
    public PageInfo<Laboratory> findLaboratoryByUnit(QueryVo queryVo) {
        PageInfo<Laboratory> laboratoryPageInfo = QueryVoUtil.getPages(
                queryVo.getPageNum(),
                queryVo.getPageSize(),
                laboratoryMapper.findLaboratoryByUnit((String) queryVo.getQuery().get("unit"))

        );
        return laboratoryPageInfo;
    }

    @Override
    public Laboratory findLaboratoryByLid(String lid) {
        return laboratoryMapper.findLaboratoryByLid(lid);
    }

    @Override
    public int addLaboratory(Laboratory laboratory) {
        return laboratoryMapper.addLaboratory(laboratory);
    }

    @Override
    public int deleteLaboratory(String lid) {
        return laboratoryMapper.deleteLaboratory(lid);
    }

    @Override
    public int updateLaboratory(Laboratory laboratory) {
        return laboratoryMapper.updateLaboratory(laboratory);
    }
}
